package com.atguigu.juc.day01.create;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Demo05ThreadPool {

    public static void main(String[] args) {
        // 1、调用 JDK 提供的工具方法创建线程池对象
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        // 2、给线程池分配任务
        executorService.execute(()->{
            // 每隔 1 秒打印当前线程名称
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);

                    System.out.println(Thread.currentThread().getName() + " is working.");

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }

}
